/*
 * snmp_asn.h
 *
 *  Created on: 2016-11-8
 *      Author: root
 */

#ifndef SNMP_ASN_H_
#define SNMP_ASN_H_
#include<stdint.h>
#include<sys/types.h>
//u_char
#ifdef __MINGW32__
#include<_bsd_types.h>
#endif
#ifndef MAX_OID_LEN
#define MAX_OID_LEN 128
#endif
//协议版本
#define SNMP_VERSION_2c     1
//PDU类型
#define SNMP_MSG_GET        0xa0 /* a0=160 */
#define SNMP_MSG_GETNEXT    0xa1 /* a1=161 */
#define SNMP_MSG_RESPONSE   0xa2 /* a2=162 */
#define SNMP_MSG_SET        0xa3 /* a3=163 */
#define SNMP_MSG_TRAP       0xa4 /* a4=164 */
#define SNMP_MSG_GETBULK    0xa5 /* a5=165 */
#define SNMP_MSG_INFORM     0xa6 /* a6=166 */
#define SNMP_MSG_TRAP2      0xa7 /* a7=167 */
#define SNMP_MSG_REPORT     0xa8 /* a8=168 */
//常见类型
#define ASN_BOOLEAN         0x01
#define ASN_INTEGER         0x02
#define ASN_BIT_STR         0x03
#define ASN_OCTET_STR       0x04
#define ASN_NULL            0x05
#define ASN_OBJECT_ID       0x06
//#define ASN_SEQUENCE        0x10
//#define ASN_SET             0x11
#define ASN_IPADDRESS       0x40
#define ASN_COUNTER         0x41
#define ASN_GAUGE           0x42
#define ASN_UNSIGNED        0x42
#define ASN_TIMETICKS       0x43
#define ASN_COUNTER64       0x46
#define ASN_UINTEGER      0x47
#define ASN_SEQUENCE        0x30
#define SNMP_NOSUCHINSTANCE 129
//编译长度包
int MakeAsnLengthData(char*data,int len,u_char type,int length);
//编译字符串
int MakeAsnStringData(char*data,int len,u_char type,const char*valstr,int vallen);
//编译ObjectID
int MakeAsnObjectIDData(char*data,int len,u_char type,uint32_t*oidName,int oidLen);
//编译整数
int MakeAsnIntData(char*data,int len,u_char type,int number,int length);
//请求数据
int MakeAsnRequestData(char*data,int len,uint32_t*oidName,int oidLen);
//读取包长
//检测类型，返回长度
const char*ReadAsnLengthData(const char*data,int len,u_char type,int&length);
//获取分割包长度
//限制ASN_SEQUENCE
const char*ReadAsnSequenceLength(const char*data,int len,int&length);
//读取整数
//限制ASN_INTEGER/ASN_GAUGE
const char*ReadAsnIntData(const char*data,int len,u_char type,int32_t&number);
//const char*ReadAsnInt32Data(const char*data,int len,u_char type,int32_t&number);
//ASN_TIMETICKS/
//const char*ReadAsnUInt32Data(const char*data,int len,u_char type,uint32_t&number);
//读取OBJECTID
//限制类型ASN_OBJECT_ID
const char*ReadAsnObjectIDData(const char*data,int len,uint32_t*oidName,int&oidLen);
//根据类型获取类型描述
const char*GetAsnTypeName(u_char type);
#endif /* SNMP_ASN_H_ */
